package com.ewzj.bigdata.mvp.model

import android.app.Application
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.extensions.json2Body
import com.ewzj.bigdata.mvp.contract.LogoContract
import com.ewzj.bigdata.mvp.contract.SplashContract
import com.ewzj.bigdata.mvp.model.reqbean.ReqAd
import com.ewzj.bigdata.mvp.model.reqbean.ReqConfigbean
import com.ewzj.bigdata.mvp.model.reqbean.ReqSearchCityBean
import com.ewzj.bigdata.mvp.model.rspbean.*
import com.google.gson.Gson
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.mvp.BaseModel
import com.jess.arms.utils.DataHelper
import io.reactivex.Observable
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class LogoModel @Inject  constructor(val application: Application,val mGson:Gson,repositoryManager: IRepositoryManager): BaseModel(repositoryManager), LogoContract.Model{
    val service=repositoryManager.obtainRetrofitService(CommonService::class.java)
    override fun getSavedCity(): CityBean.ListEntity {
        val city=DataHelper.getStringSF(application,AppKey.LOCATION_CITY)
        val savedcity=mGson.fromJson(city,CityBean.ListEntity::class.java)
        return savedcity
    }

    override fun getconfigInfo(): Observable<BaseData<ConfigBean>> {
        return service.getconfig(json2Body(mGson.toJson(ReqConfigbean("app_version"))))
    }

    override fun getAdList(): Observable<BaseData<AdBean>> {
        return service.getAdlist(json2Body(mGson.toJson(ReqAd("1"))))
    }

    override fun getCityByname(city: String):  Observable<BaseData<CitySearchBean>> {
        val reqcitysearch= ReqSearchCityBean(city)
        return service.getcitybyname(json2Body(mGson.toJson(reqcitysearch)))
    }
}